CXX := g++
PKG := pkg-config

# 生成代码在 generated/ 下，源码里直接 #include "hello.pb.h"

CXXFLAGS := -std=c++17 -Wall -pthread \
            $(shell $(PKG) --cflags protobuf grpc++)
# LDLIBS := $(shell pkg-config --libs protobuf grpc++)，这样如果系统里的 libprotobuf/libgrpc++ 
#还依赖其他库（比如某些发行版会额外带上 -lz、-labsl_* 等），会自动带上，不会漏
LDLIBS := $(shell $(PKG) --libs protobuf grpc++)

GEN_SRCS := generated/hello.pb.cc generated/hello.grpc.pb.cc
SERVER_SRCS := server/server.cc $(GEN_SRCS)
CLIENT_SRCS := client/client.cc $(GEN_SRCS)

SERVER_BIN := RPCserver
CLIENT_BIN := RPCclient

all: $(SERVER_BIN) $(CLIENT_BIN)

$(SERVER_BIN): $(SERVER_SRCS)
	$(CXX) $(CXXFLAGS) $^ -o $@ $(LDLIBS)

$(CLIENT_BIN): $(CLIENT_SRCS)
	$(CXX) $(CXXFLAGS) $^ -o $@ $(LDLIBS)

clean:
	rm -f $(SERVER_BIN) $(CLIENT_BIN)